#include "lv_port.h"
#include "rgb_lcd.h"
#include "sdram.hpp"

uint16_t *buf_2_1 = (uint16_t *)((uint32_t)(0xC0000000 + 800*480*2));

static void disp_flush(lv_display_t * disp_drv, const lv_area_t * area, uint8_t * px_map)
{
    rgb_colors_fill(area->x1, area->y1, area->x2, area->y2, (uint16_t *)px_map);
}

void lv_port_disp_init()
{
    sdram_init();

    static lv_display_t *disp = lv_display_create(MY_DISP_HOR_RES, MY_DISP_VER_RES);
    lv_display_set_flush_cb(disp, disp_flush);

    extern DMA2D_HandleTypeDef hdma2d;
    hdma2d.XferCpltCallback = [](DMA2D_HandleTypeDef *hdma2d) { lv_disp_flush_ready(disp); };

    lv_display_set_buffers(disp, buf_2_1, NULL, 2*800*480, LV_DISPLAY_RENDER_MODE_PARTIAL);
}


